package com.ccc.javacv.response;

import java.io.Serializable;

public class ResponseResult implements Serializable {
    private static final long serialVersionUID = -6770538785772264261L;

    private boolean success = true;
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 消息
     */
    private String message;

    /**
     * 需要返回的数据对象
     */
    private Object data;

    public ResponseResult() {
        super();
    }

    /**
     * 一般的响应结果，不返回数据，自定义消息
     *
     * @param code    {@link Integer} 自定义状态码
     * @param message {@link String} 自定义消息
     */
    public ResponseResult(Integer code, String message) {
        super();
        this.code = code;
        this.message = message;
    }

    /**
     * 一般的响应结果，自定义消息并包含数据
     *
     * @param code    {@link Integer}
     * @param message {@link String}
     * @param data    {@link Object}
     */
    public ResponseResult(Integer code, String message, Object data) {
        super();
        this.code = code;
        this.message = message;
        this.data = data;
    }


    /**
     * 请求成功
     *
     * @return this
     */
    public static ResponseResult success() {
        return new ResponseResult(200, "请求成功");
    }

    /**
     * 请求成功
     *
     * @return this
     */
    public static ResponseResult success(String message, Object data) {
        return new ResponseResult(200, message, data);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public boolean isSuccess() {
        return success;
    }

    public ResponseResult setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public ResponseResult setMessage(String message) {
        this.message = message;
        return this;
    }

    public Object getData() {
        return data;
    }

    public ResponseResult setData(Object data) {
        this.data = data;
        return this;
    }

    /**
     * toString
     */
    @Override
    public String toString() {
        return "ResponseResult{" +
                "success=" + success +
                ", code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
